home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / COMMUNIC / H191.ZIP / CA29-3.EXE / SETTIME.CMD < prev    next >
OS/2 REXX Batch file  |  1993-04-19  |  4KB  |  138 lines

  1. S0 = "CdT"              ; values are: EST, CST, MST, PST, EDT, CDT, MDT, PDT
  2. ;
  3. ; ----- COM-AND set DOS clock
  4. ;
  5. ;    This script dials the US Naval Observatory and sets the DOS clock
  6. ;    with the time obtained.  NOTE: If you change this script, please
  7. ;    do not connect to the Observatory longer than absolutely required.
  8. ;    Courteous usage will most likely retain this service.
  9. ;
  10. ;    S0 should be set with your timezone (EST, CST, MST, or PST)... if
  11. ;    left blank, this script will look for an EBL variable &ZONE... if
  12. ;    that is not found, this script will ask for it.
  13. ;
  14. ;    Note that this script, as supplied, only invokes DOS's TIME command
  15. ;    to set the clock.  If you have a hardware clock, the TIME command of
  16. ;    DOS will not necessarily change the hardware clock (and thus last
  17. ;    accross a power off).
  18. ;
  19. ;    The value in S0, if supplied, establishes the timezone.  You must
  20. ;    manually decide (for now) if daylight savings is used in your area.
  21. ;
  22. ; ------------------------------------------------------------
  23. ;    Script: John Poindexter, commenced 2/89
  24. ;        Modified for scheduler       4/93
  25. ; ------------------------------------------------------------
  26. ;
  27. ;    If the value in S0 is null, look for EBL's &ZONE
  28. ;    .. This script does not require EBL if the above is set.
  29. ;
  30. LEGEND "SETTIME v1.0"
  31. IF NULL S0        ; If value not set above
  32.    EBL S0 &ZONE     ; .. Ask EBL if it knows the zone
  33. ELSE            ; If set above
  34.    SET SUCCESS ON    ; .. Fake EBL good completion
  35.    ENDIF
  36. ;
  37. ;    If no EBL and no value, open a window and ask
  38. ;
  39. IF FAILED        ; No zone in script, and no EBL
  40.    WOPEN 10,1, 13,77 (contrast) Exit
  41.    ATSAY 11, 3 (contrast) "Enter your timezone (EST, EDT, CST, CDT, ...)"
  42.    ATSAY 12, 3 (contrast) "->"
  43.    ATSAY 13,26 (contrast) " Press ESC to exit"
  44.    ATGET 12,6  (contrast) 3 S0
  45.    WCLOSE        ; Restore screen under
  46.    IF NULL S0 GOTO Exit ; Null entry terminates script
  47.    ENDIF
  48. ;
  49. ;    Using the Zone value, look up the hour offset
  50. ;
  51. S1 = "E5C6M7P8"         ; Time zone letters and time difference from GMT.
  52. FIND S1 S0(0:0) N0    ; Case insensitive table lookup
  53. IF NOT FOUND        ; Unknown zone character
  54.    MESSAGE "^M^JYou need to include your time zone in S1 in script.^M^J"
  55.    GOTO EXIT
  56.    ENDIF
  57. ;
  58. ;    COmpute the hour offset (allowing for DAYLIGHT Savings)
  59. ;
  60. S1 = S1(N0+1:N0+1)    ; Take hour offset from table
  61. ATOI S1 N0        ; COnvert to binary (w/o error message)
  62. IF FIND S0 "D"          ; Look for daylight savings time
  63.    N0 = N0 - 1        ; Adjust for daylight savings
  64.    ENDIF
  65. ;
  66. ;    Set-up to dial the Naval Observatory
  67. ;
  68. SET FLAG(0) OFF     ; Flag indicates wrap to previous day
  69. ON ESCAPE GOSUB UNAVAILABLE
  70.  
  71. IF FIND "_DDOVER" "OFF" SET BAUD 1200 ; Set parms for USNO (1200...)
  72. SET PARITY NONE     ; .. (n,8,1)
  73. SET DATA 8        ; ..
  74. SET STOP 1        ; ..
  75. SET MDEL 30        ; Slow it down
  76. ;
  77. ;    Dial the Naval Observatory
  78. ;
  79.    N99 = 1
  80. LOOP:
  81.    LEGEND "SETTIME v1.0 dialing attempt #"*N99
  82.    TRANSMIT "_MESCa"&"!"; Wake up the modem
  83.    PAUSE 1
  84.    TRANSMIT "_DPREf"&"1-202-653-0351"&"_DSUFf"&""  ; Dialing command
  85.  
  86.    WAITFOR  "_MCONn"&"" 45 ; Remember to trim trailing blanks
  87.    IF NOT WAITFOR    ; DIAL failed
  88.       TRANSMIT "_MESCa"&"!"
  89.       TRANSMIT "_MHANg"&""
  90.       INC N99        ; COunt the try
  91.       IF N99 GT 10 GOTO Unavailable
  92.       GOTO LOOP
  93.       ENDIF
  94. ;
  95. ;    Read the UTC
  96. ;
  97. GET_TIME:
  98.    WAITFOR "*" 30
  99.    RGET S0
  100.    RGET S0
  101.    MESSAGE S0
  102.    IF NOT FIND S0(17:19) "UTC"
  103.       GOTO GET_TIME
  104.       ENDIF
  105. ;
  106. ;    Extract the time from the message
  107. ;
  108. ATOI S0(10:11) N1    ; Extract hour #
  109. IF LT N1 N0        ; Test for negative after adjust
  110.    N1 = N1 + 24     ; Ensure positive hour number after adjust
  111.    SET FLAG(0) ON    ; .. and flag the fact
  112.    ENDIF
  113. ;
  114. ;    And give the TIME to DOS
  115. ;
  116. TIME S3 1        ; Save current clock
  117. N1 = N1 - N0        ; Adjust for timezone
  118. S1 = "TIME "*N1&":"&S0(12:13)&":"&S0(14:15)
  119. DOS S1            ; Tell DOS to set the clock
  120. MESSAGE S1        ; Display on screen too
  121. CLOG "* SETTIME clock change from:" *S3*" to "*S1(5:79)
  122. HANGUP
  123. GOTO Exit
  124. ;
  125. ;    Failed DIAL
  126. ;
  127. UNAVAILABLE:
  128.    HANGUP
  129.    MESSAGE "^M^JUnable to reach the Naval Observatory.^M^J"
  130.    GOTO Exit
  131. ;
  132. ;    General exit (modem not connected yet)
  133. ;
  134. EXIT:
  135.    IF ISSC "$$$SCHED" EXECUTE "$$$SCHED"
  136.    IF FCALLED FRETURN    ; Return if called
  137.    EXIT
  138.